<!DOCTYPE html>
<html>
<head>
<title>ajax03.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
	function getXhr() {
		var xhr = null;
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else {
			xhr = new ActiveXObject("Microsoft.XMLHttp");
		}
		return xhr;
	}

	function getText() {
		//1.获取Ajax对象
		var xhr = getXhr();
		//2.设置回调函数
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4 && xhr.status == 200) {
				var txt = xhr.responseText;
				alert(txt);
			}
		};
		xhr.open("post", "post_text.do", true);
		xhr.setRequestHeader('content-type',
				'application/x-www-form-urlencoded');
		xhr.send("uname=Dr.");
	}
</script>
</head>

<body>
	<input type="button" onclick="getText()" value="post请求" />
	<a href="javascript:;" onclick="getText()">post请求2</a>
</body>
</html>
